先把how2j的io教程过一遍 how2j的io教程
1.文件对象
1 | File f = new File("d:/LOLFolder/LOL.exe"); |
1.2 遍历文件夹
2.流就是一系列数据
- inputStream outputStream
- FileInputStream文件输入流 FileOutputStream文件输出流
- 没有byteInputStream ….
- DataInputStream 数据输入流 DataOutputStream 数据输出流
1 | //准备文件lol.txt其中的内容是AB,对应的ASCII分别是65 66 |
4.中文问题 见how2j
5.缓存字符输入流 BufferedReader
1 | File f = new File("d:/lol.txt"); |
6.
再学习入职培训的io(规定使用公司提供的工具)
io常用类 BufferedWriter BufferedReader InputStream OutputStream
- System.getProperty(“java.io.tmpdir”) java运行产生的临时文件目录
- File.separator 字符“/”
再加文件名
InputStream in = Test.class .getResourceAsStream("/com/fangjun/esensoft2/util/grade1.txt"); OutputStream out=new FileOutputStream( new File(System.getProperty("java.io.tmpdir")+File.separator+"111.txt")); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(out)); bw.write("+----------------------------------------------); BufferedReader br = new BufferedReader(new InputStreamReader( in, "UTF-8")); try { String line = br.readLine(); while (line != null) { Grade pGrade = line2Grade(line); list.add(pGrade); line = br.readLine(); } } finally { br.close(); }